<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="description" content="Partytown Test Page" />
    <title>Navigator</title>
    <style>
      body {
        font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif,
          Apple Color Emoji, Segoe UI Emoji;
        font-size: 12px;
      }
      h1 {
        margin: 0 0 15px 0;
      }
      ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
      }
      a {
        display: block;
        padding: 16px 8px;
      }
      a:link,
      a:visited {
        text-decoration: none;
        color: blue;
      }
      a:hover {
        background-color: #eee;
      }
      li {
        display: flex;
        margin: 15px 0;
      }
      li strong,
      li code,
      li button {
        white-space: nowrap;
        flex: 1;
        margin: 0 5px;
      }
    </style>
    <script>
      partytown = {
        logCalls: true,
        logGetters: true,
        logSetters: true,
        logStackTraces: false,
        logScriptExecution: true,
        resolveSendBeaconRequestParameters: (url, location) => {
          if (url.searchParams.has('withParams')) {
            return {
              keepalive: false,
              mode: 'same-origin',
              cache: 'no-cache',
              headers: new Headers({
                'custom-header': 'custom-value'
              })
            };
          }
        }
      };
    </script>
    <script src="/~partytown/debug/partytown.js"></script>
  </head>
  <body>
    <h1>Navigator</h1>
    <ul>
      <li>
        <strong>userAgent</strong>
        <code id="testUserAgent"></code>
        <script type="text/partytown">
          (function () {
            const elm = document.getElementById('testUserAgent');
            elm.textContent = navigator.userAgent;
            elm.className = 'testUserAgent';
          })();
        </script>
      </li>

      <li>
        <strong>sendBeacon()</strong>
        <code id="testSendBeacon"></code>
        <script type="text/partytown">
          (function () {
            const elm = document.getElementById('testSendBeacon');
            const formData = new FormData();
            formData.append('name', 'value');
            const success = navigator.sendBeacon('api.js', formData);
            elm.textContent = success;
            elm.className = 'testSendBeacon';
          })();
        </script>
      </li>
      <li>
        <strong>sendBeacon() resolveParams</strong>
        <code id="testSendBeaconResolveParams"></code>
        <script type="text/partytown">
          (function () {
            const elm = document.getElementById('testSendBeaconResolveParams');
            const formData = new FormData();
            formData.append('name', 'value');
            const success = navigator.sendBeacon('api.js?withParams=1', formData);
            elm.textContent = success;
            elm.className = 'testSendBeaconResolveParams';
          })();
        </script>
      </li>
      <li>
        <strong>Assign value 5 to navigator.a</strong>
        <code id="testNavKey"></code>
        <script type="text/partytown">
          (function () {
            const elm = document.getElementById('testNavKey');
            navigator.a=5;
            elm.textContent = navigator.a;
            elm.className = 'testNavKey';
          })();
        </script>
      </li>
      <li>
        <strong>Properties defined in global navigator but not in the worker instance</strong>
        <code id="testMainNavigatorProperties"></code>
        <script type="text/partytown">
          (function () {
            const elm = document.getElementById('testMainNavigatorProperties');
            navigator.undefinedProp = undefined;
            navigator.nullProp = null;
            navigator.falseProp = false;
            navigator.emptyStringProp = "";
            elm.textContent = JSON.stringify({
              javaEnabled: navigator.javaEnabled(),
              cookieEnabled: navigator.cookieEnabled,
              undefinedProp: navigator.undefinedProp ? 'is_defined' : 'is_undefined',
              nullProp: navigator.nullProp,
              falseProp: navigator.falseProp,
              emptyStringProp: navigator.emptyStringProp,
              newProperty: navigator.newProperty ? 'is_defined' : 'is_undefined',
              pdfViewerEnabled: typeof navigator.pdfViewerEnabled === 'boolean' ? 'available' : 'undefined',
              plugins: typeof navigator.plugins.length === 'number' ? 'available' : 'undefined',
            });
            elm.className = 'testMainNavigatorProperties';
          })();
        </script>
      </li>
    </ul>

    <hr />
    <p><a href="/tests/">All Tests</a></p>
  </body>
</html>
